#ifndef SOLUTION_H_
#define SOLUTION_H_
struct ListNode {
      int val;
      ListNode *next;
      ListNode(int x) : val(x), next(0) {}
  };

class Solution {
public:
    ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        int carry = 0;
		ListNode* head = 0;
		ListNode* cur = head;
		

		/*ListNode* cur1 = l1;
		ListNode* cur2 = l2;*/

		while( l1 || l2 || carry ){
			if(cur)
			{
				cur->next = new ListNode(0);
				cur = cur->next;
			}
			else{
				head = cur = new ListNode(0);
			}

			int t = 0;
			t += carry;
			if(l1){
				t += l1->val;
				l1 = l1->next;
			}
			if(l2){
				t += l2->val;
				l2 = l2->next;
			}

			cur->val = t % 10;
			carry = t / 10;
		}

		return head;
    }
};
#endif